package com.lsp.data.net;

import rx.Observable;
import rx.Subscriber;
import rx.subscriptions.CompositeSubscription;

/**
 * @author com.lsp.ibxs
 * @created 16/11/10 15:27
 */
public interface RetrofitCallManager {

  <T> void manageRetrofitCall(Observable<T> observable, Subscriber<T> subscriber);

  /**
   * 请求实现类
   */
  class RetrofitCallManagerImpl implements RetrofitCallManager {

    private CompositeSubscription mCompositeSubscription = new CompositeSubscription();

    @Override
    public <T> void manageRetrofitCall(Observable<T> observable, Subscriber<T> subscriber) {
      mCompositeSubscription.add(observable.subscribe(subscriber));
    }

    public void unSubscribeAll() {
      mCompositeSubscription.unsubscribe();
    }
  }
}
